/**
 * @modal: 智能策略手动&自动执行记录
 */
import CommonModal from '@/components/CommonModal';
import { Button } from 'antd';
import { useState, useEffect } from "react";


function ExecuteSure({ handleOk, handleCancel }) {

	const [open, setOpen] = useState(false);

	//点否点击确定按钮
	const [isOk, setIsOk] = useState(1);

	useEffect(() => {
		setOpen(true);
	}, []);

	//点击确定
	const executeOld = () => {
		setIsOk(2);
		setOpen(false);
	}

	const executeNew = () => {
		setIsOk(3);
		setOpen(false);
	}

	const onCancel = () => {
		setOpen(false);
	};

	const afterClose = () => {
		if (isOk == 1) {
			handleCancel();
		} else {
			handleOk(isOk);
		}
	};

	const footer = (
		<>
			<Button onClick={executeOld}>不保存，只执行旧规则</Button>
			<Button onClick={executeNew} type="primary">保存并执行</Button>
		</>
	)

	return (
		<CommonModal
			title="手动执行提示"
			afterClose={afterClose}
			open={open}
			width="520px"
			footer={footer}
			onCancel={onCancel}
		>
			<h3>当前规则有操作修改但未保存，需要保存+执行吗？</h3>
		</CommonModal>
	);
}

export default ExecuteSure;
